Automation from CI Pipelines

Argo CD follows the GitOps model of deployment, where desired configuration changes are first pushed to Git, and the cluster state then syncs to the desired state in git. This is a departure from imperative pipelines which do not traditionally use Git repositories to hold application config.

To push new container images into to a cluster managed by Argo CD, the following workflow (or variations), might be used:

Build And Publish A New Container Image

  1. docker build -t mycompany/guestbook:v2.0 .
  2. docker push mycompany/guestbook:v2.0

Update The Local Manifests Using Your Preferred Templating Tool, And Push The Changes To Git

Tip

The use of a different Git repository to hold your Kubernetes manifests (separate from your application source code), is highly recommended. See best practices for further rationale.

  1. git clone https://github.com/mycompany/guestbook-config.git
  2. cd guestbook-config
  3. # kustomize
  4. kustomize edit set image mycompany/guestbook:v2.0
  5. # plain yaml
  6. kubectl patch --local -f config-deployment.yaml -p '{"spec":{"template":{"spec":{"containers":[{"name":"guestbook","image":"mycompany/guestbook:v2.0"}]}}}}' -o yaml
  7. git add . -m "Update guestbook to v2.0"
  8. git push

Synchronize The App (Optional)

For convenience, the argocd CLI can be downloaded directly from the API server. This is useful so that the CLI used in the CI pipeline is always kept in-sync and uses argocd binary that is always compatible with the Argo CD API server.

  1. export ARGOCD_SERVER=argocd.example.com
  2. export ARGOCD_AUTH_TOKEN=<JWT token generated from project>
  3. curl -sSL -o /usr/local/bin/argocd https://${ARGOCD_SERVER}/download/argocd-linux-amd64
  4. argocd app sync guestbook
  5. argocd app wait guestbook

If automated synchronization is configured for the application, this step is unnecessary. The controller will automatically detect the new config (fast tracked using a webhook, or polled every 3 minutes), and automatically sync the new manifests.